export * from "./static";
import { gd, format, pd, apiUrl, existUni, next, request, setRequestBefore, setBaseUrl, upq, api, login } from "./static";
setBaseUrl(apiUrl);

export function onLoaded(callback: cbk) {
  uni.$on("loaded", callback);
  callback();
}
export async function getSetting(id: string) {
  return ((await gd.setting.getById(id)) || { value: "" }).value as string;
}

export function navigateTo(url?: string, params?: obj) {
  return url ? uni.navigateTo({ url: upq(url, params) }) : undefined;
}
export function back() {
  const s = getCurrentPages();
  // #ifdef H5
  if (s.length === 1 && history.length > 1 && history.state.back) {
    history.back();
    return;
  }
  // #endif
  uni.navigateBack();
}
export function isTemporaryFileUrl(url: string) {
  return url.startsWith('https:') || url.startsWith('http:') ? false : true;
}
export function currentPage() {
  const s = getCurrentPages();
  if (Array.isArray(s) && s.length) {
    return s[s.length - 1];
  }
}
export function cr(): string {
  const r: any = currentPage();
  return r?.$page?.path || "";
}
export function crf(): string {
  const r: any = currentPage();
  return r?.$page?.fullPath || "";
}
